﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;

namespace SRM.Modules
{
    public class Email
    {
        public static void SendTestEmail()
        {
            SendEmail("zhixian.ong@keppelland.com", "TEST", "TEST EMAIL", false);
        }

        public static void SendEmail(string emailAddress, string emailSubject, string emailBody, bool isBodyHtml)
        {
            string SmtpServer = System.Configuration.ConfigurationManager.AppSettings["Smtp_Server"];
            string SenderEmail = System.Configuration.ConfigurationManager.AppSettings["Sender_Email"];
            string SenderName = System.Configuration.ConfigurationManager.AppSettings["Sender_Name"];
            string EmailQueuePath = System.Configuration.ConfigurationManager.AppSettings["Email_Queue_Path"];
            string DeveloperEmail = System.Configuration.ConfigurationManager.AppSettings["Developer_Email"];
            string DeveloperName = System.Configuration.ConfigurationManager.AppSettings["Developer_Name"];

            const string Email_CharSet = "UTF-8";

            ASPEMAILLib.IMailSender mailMessage = new ASPEMAILLib.MailSender();
            mailMessage = new ASPEMAILLib.MailSender();
            mailMessage.Host = SmtpServer;
            mailMessage.From = SenderEmail;
            mailMessage.FromName = mailMessage.EncodeHeader(SenderName, Email_CharSet);

            mailMessage.CharSet = Email_CharSet;
            mailMessage.ContentTransferEncoding = "Quoted-Printable";
            mailMessage.Subject = mailMessage.EncodeHeader(emailSubject, Email_CharSet);

            mailMessage.AddAddress(emailAddress);
            mailMessage.Body = emailBody;
            mailMessage.IsHTML = isBodyHtml? 1 : 0;
            mailMessage.Queue = 0;
            mailMessage.Send();
            mailMessage.Queue = 1;
            mailMessage.Send(EmailQueuePath);
        }
    }
}